package com.chenshu.controller;

import com.chenshu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-11
 * Time：21:31
 */
@Controller
public class SController {

    //1.属性注入
//    @Autowired
//    private Student student;
    private Student student;
    private Teacher teacher;
    Integer number;
    //2.Setter注入
//    @Autowired
//    public void setStudent(Student student) {
//        this.student = student;
//    }

    //3.Construction注入
    @Autowired
    public SController(Student student) {
        this.student = student;
    }

    public SController(Student student, Teacher teacher) {
        this.student  = student;
        this.teacher = teacher;
    }


    public void doController() {
        System.out.println("Do school controller");
        if (student != null) {
            student.setId(1);
            student.setName("chenshu");
            System.out.println("Id:" + student.getId() + " | " + "name:" + student.getName());
        } else {
            System.out.println("student == null");
        }
        if (teacher != null) {
            teacher.setId(1);
            teacher.setName("Mr.chen");
            System.out.println("Id:" + teacher.getId() + " | " + "name:" + teacher.getName());
        } else {
            System.out.println("teacher == null");
        }
    }
}
